import Vue from 'vue'
import Vuex from 'vuex'
import user from './ljp/user.js'
import set from './ljp/set.js'

Vue.use(Vuex)

const store = new Vuex.Store({
    //所有组件共享的数据
    state: {
        count:100,
        title:"大标题",
        list:[1,2,3,4,5,6,7,8,9]
    },
    //提供方法，操作state中的数据
    mutations: {
        funAddOne(state,value){
            state.count += value
        },
        funRedOne(state,value){
            state.count -= value
        },
        delayOne(state,value){
            state.count = value
        }
    },
    //处理异步，不是直接操作state，先commit mutations
    actions: {
        changeOne(context,value){
            setTimeout(()=>{
                context.commit('delayOne',value)
            },1000)
        }
    },
    //类似于计算属性
    getters:{
        filter(state){
            return state.list.filter((item)=>{
                return item>5
            })
        }
    },
    modules:{
        user,
        set
    }
})

export default store